package cn.lena.weblog.controller;

import cn.lena.weblog.service.KeywordService;
import cn.lena.weblog.service.PassageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/keyword")
public class KeywordController {

	@Autowired
	private KeywordService keywordService;

	@Autowired
	private PassageService passageService;

	@RequestMapping("/findPassage/{id}")	//t
	public String findPassage(@PathVariable Integer id, Model model,HttpSession session){
		if (session.getAttribute("user") == null) {
			model.addAttribute("login",false);
		}else{
			model.addAttribute("login",true);
		}
		model.addAttribute("currentKId",id);
		model.addAttribute("keywords",keywordService.findTop10());
		model.addAttribute("kPassages",passageService.findByKeyword(id));
		return "keyword";
	}

}
